package com.briup.jz.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.briup.jz.bean.BaseFile;
import com.briup.jz.bean.BaseFileExample;
import com.briup.jz.dao.BaseFileMapper;
import com.briup.jz.service.IFileService;
import com.briup.jz.utils.CustomerException;

@Service
public class BaseFileServiceImpl implements IFileService{
 @Autowired
 private BaseFileMapper basefileMapper;

 
 
 @Override
 public void saveOrUpdate(BaseFile basefile) throws CustomerException {
  // TODO Auto-generated method stub
  if(basefile.getId()!=null) {
   basefileMapper.updateByPrimaryKey(basefile);
  } else {
   // 判断是否有同名的分类，如果有抛出异常
   BaseFileExample example = new BaseFileExample();
  example.createCriteria().andFileNameEqualTo(basefile.getFileName());
  List<BaseFile> list = basefileMapper.selectByExample(example);
   if(list.size()>0) {
    throw new CustomerException("同名的filename已存在");
   }
   basefileMapper.insert(basefile);
  }
 }

 @Override
 public List<BaseFile> query(Long id) {
  // TODO Auto-generated method stub
  BaseFileExample example = new BaseFileExample();
  if(id!=null){
  }
  List<BaseFile> list = basefileMapper.selectByExample(example);
  return list;
 
 }

 @Override
 public void deleteById(String id) throws CustomerException {
  // TODO Auto-generated method stub
  //BaseFileExample example = new BaseFileExample();
  BaseFile basefile = basefileMapper.selectByPrimaryKey(id);
  if(basefile == null) {
   throw new CustomerException("要删除的日志信息不存在");
  }
  basefileMapper.deleteByPrimaryKey(id);
  
 }
  
 }
